package giftmail.netty;

import java.util.concurrent.Executors;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;

public class DiscardServer {

	public static void main(String[] args) {
		//ChannelFactory工厂不创建IO线程，在构造器中指定使用的线程
		ChannelFactory factory = new NioServerSocketChannelFactory(
				Executors.newCachedThreadPool(),
				Executors.newCachedThreadPool()
				);
		//服务的帮助类,获取pipeline()
		ServerBootstrap bootstrap = new ServerBootstrap(factory);
		
		//任何时候，当服务器收到新的连接，新的ChannelPipeline管道就被创建
		ChannelPipeline pipeline = bootstrap.getPipeline();
		DiscardServerHandler discardServerHandler = new DiscardServerHandler();
		pipeline.addLast("handler", discardServerHandler);
		
		//TCP/IP服务，设定一些socket选项
		//child.意味着
		//TCP/IP
		//child
		bootstrap.setOption("child.tcpNoDelay", true);
		bootstrap.setOption("child.keepAlive", true);
	}

}
